#写函数，计算传⼊的字符串中数字，字⺟，空格，以及其他的个数
import numbers
from operator import index


def calc(str1):
    count1 = len([i for i in str1 if i.isdigit()])
    count2 = len([i for i in str1  if i.isalpha()])
    count3 = len([i for i in str1 if i.isspace()])
    count4 = len(str1)-count1-count2-count3
    print("数字个数：%d:\n字母个数%d:\n空格个数:%d\n其他个数:%d"%(count1,count2,count3,count4))
#写函数，判断⽤⼾传⼊的对象（字符串，列表，元组）⻓度是否⼤于5
def calc1(str):
    if len(str) > 5:
        print("长度大于5")
    else:
        print("长度不大于5")

#写函数监测⽤⼾传⼊的对象（字符，列表，元组）的每⼀个元素是否有空内容
def calc2(str):
    flag = False
    for i in str:
        if i == "" or i ==" ":
            flag = True
    if flag:
        print("有空类型")
    else:
        print("无空类型")


#写函数，检查传⼊列表的⻓度，如果⼤于2，那么仅仅保留前两个⻓度的内容，并将新内容返回给调⽤者
def calc3(str):
    length = len(str)
    if length > 2:
        return [i for i in str if str.index(i)<2]

#写函数，检查获取传⼊列表或元组的所有奇数位索引对应的元素，并将其作为新列表返回给调用者
def calc4(str):
    return [i for i in str if str.index(i) % 2 == 1]

#写函数，计算传⼊字符串中的【数字】、【字⺟】、【空格】和【其他】的个数
def calc5(str1):
    num = ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9")
    character = ("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z")
    space = (" ")
    count1 = len([i for i in str1 if i in num])
    count2 = len([i for i in str1  if i in character])
    count3 = len([i for i in str1 if i in space])
    count4 = len(str1)-count1-count2-count3
    print("数字个数：%d:\n字母个数%d:\n空格个数:%d\n其他个数:%d"%(count1,count2,count3,count4))